'use strict';
const amqp = require('amqplib');
const URL = 'amqp://lihua:lihua@121.37.94.144:5672';

// const connection = amqp.connect(URL);

// const getChannel =async ()=>{
//   connection.then(conn=>{
//     return conn.createChannel();
//   })
// }

const publishMessage =async (exchangeName,queueName,routeingKey,message)=>{
    const connect = await amqp.connect(URL);
    const channel = await connect.createChannel();
    await channel.assertExchange(exchangeName, 'direct', { durable: true });
    channel.publish(exchangeName, routeingKey, Buffer.from(message));
    setTimeout(async ()=>{
      await connect.close();
    },100)
    
}

module.exports = {
  // getChannel,
  publishMessage
};
